<template>
  <div>
    <el-card>
      <el-button type="info" icon="el-icon-edit" @click="fanhui()">返回车队列表</el-button>
      <el-table v-loading="loading" :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="车辆编号">
        </el-table-column>
        <el-table-column prop="truckName" label="车辆类型">
        </el-table-column>
        <el-table-column prop="licensePlate" label="车牌号码">
        </el-table-column>
        <el-table-column prop="fleetName" label="所属车队">
        </el-table-column>
        <el-table-column prop="deviceGpsId" label="GPS设备ID">
        </el-table-column>
        <el-table-column prop="allowableLoad" label="准载重量(千克)">
        </el-table-column>
        <el-table-column prop="allowableVolume" label="准载体积(方)">
        </el-table-column>
        <el-table-column prop="status" label="过期状态">
        </el-table-column>
        <el-table-column prop="transportTripsId" label="车次编号">
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="150">
          <template slot-scope="scope">
            <el-button type="text" size="medium " @click="findDetails(scope.row)">查看详情</el-button>
            <el-button style="color: red" type="text" size="medium" @click="remTruck(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="setSize"
        @current-change="setPage"
        :current-page="pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagesum">
      </el-pagination>
    </el-card>
  </div>
</template>
<script>

import method from '../../../api/logisticsmanagement/transitcenter/truckManagement'

export default {
  name: "vehicleManagement",
  data() {
    return {
      //  当前页
      pagenum: 1,
      //  一页显示几条数据
      pagesize: 3,
      //  总页数
      pagesum: 0,
      //  查询出来的数据
      tableData: [],
      //  所有车辆类型数据
      truckTypeData: [],
      //  所有车队数据
      fleetData: [],
      //  table的加载状态
      loading: false,
      //  添加对话框的状态
      dialogVisible: false,
      //  添加对话框的数据
      addTruckData: {
        "truckTypeId": "",
        "licensePlate": "",
        "fleetId": "",
        "deviceGpsId": "",
        "allowableLoad": "",
        "allowableVolume": "",
      }
    }
  },
  methods: {
    //  返回车队列表
    fanhui() {
      this.$router.push({path:'carTeam'})
    },
    //  查询所有分页信息
    findPageTruck() {
      this.loading = true
      let tiaojian = {
        fleetId:this.$route.query.fleetid
      }
      method.selTruckAll(this.pagenum,this.pagesize,tiaojian).then(({data}) => {
        this.tableData = data.data.records
        this.pagesum = data.data.total
        this.loading = false
      })
    },
    //  设置一页显示多少数据
    setSize(val) {

      this.pagesize = val
      this.findPageTruck()
    },
    //  设置一页显示多少数据
    setPage(val) {

      this.pagenum = val
      this.findPageTruck()

    },
    //  查看车辆详情
    findDetails(val) {
      this.$router.push({path:'truckDetails',query: {id:val.id,operate:"fleet",fleetid:this.$route.query.fleetid}})
    },
    //  删除车辆
    remTruck(val) {

      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        method.delTruck(val.id).then(({data}) => {
          if(data.code == 200){
            this.$notify({
              title: '成功',
              message: '车辆删除成功!',
              type: 'success'
            });
            this.findPageTruck()
          }
          if(data.code == 203){
            this.$message.error('您的权限不够!');
            return
          }
          if(data.code == 201){

            this.$notify({
              title: '警告',
              message: data.message,
              type: 'warning'
            })
            return
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    },
    //  取消添加对话框
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    }
  },
  created() {
    this.findPageTruck()
  }

}
</script>
